package com.yocard.yxyd.ui.presenter;

import com.google.gson.JsonObject;
import com.yocard.yxyd.base.CommonSubscriber;
import com.yocard.yxyd.base.RxPresenter;
import com.yocard.yxyd.http.HttpManager;
import com.yocard.yxyd.ui.contract.ChangePhoneContract;
import com.yocard.yxyd.utils.RxUtil;

import java.util.List;

import javax.inject.Inject;

/**
 * Created on 2019/4/18.
 */
public class ChangePhonePresenter extends RxPresenter<ChangePhoneContract.View> implements ChangePhoneContract.Presenter {

    @Inject
    public ChangePhonePresenter(HttpManager manager) {
        super(manager);
    }

    @Override
    public void getNewMobileCode(String mobile) {
        addSubscribe(httpManager.getNewMObileCode(mobile).compose(RxUtil.rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<JsonObject>(mView) {
                    @Override
                    public void onSuccess(JsonObject data) {
                        mView.showErrorMsg("验证码获取成功");
                        mView.onNewCodeGet();
                    }
                }));
    }

    @Override
    public void changeMobile(String code, String mobile) {
        addSubscribe(httpManager.changeMobile(mobile,code).compose(RxUtil.rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<List<Object>>(mView) {
                    @Override
                    public void onSuccess(List<Object> data) {
                        mView.OnChangeSuccess();
                    }
                }));
    }

}
